/*!
 * \file frreport_session_mng_clean.c
 *
 * All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.\n
 *
 * \version 3.0
 * \author geyh
 * \date 2016/03/31
 *
 */
#include <CUnit/Basic.h>
#include <stdlib.h>

#include "frcomm.h"
#include "frmem.h"
#include "apmtest_cunit.h"
#include "frhex_dump.h"
#include "frlist.h"
#include "frhash2.h"
#include "conntrack.h"
#include "frreport_comm.h"
#include "frct_comm.h"
#include "frdb_cursor.h"
#include "frreport_session_mng.h"
#include "frreport_session_comm.h"

#include "apmtest_comm.h"

static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}


extern Frhash_header *g_p_st_hash_data;
extern Frhash_header *g_p_st_hash_node_free;

FR_STATIC Frexp_ref g_st_expRef={NULL, NULL};
FR_STATIC Frservice_ref g_st_serviceRef={NULL, NULL};
FR_STATIC Frreport_session_ref g_st_report_session_Ref={NULL, NULL, NULL};
FR_STATIC Report_module g_st_report_moduleRef = {NULL, NULL, NULL, NULL, NULL};
ApmContext g_st_apm_context = {&g_st_expRef, &g_st_serviceRef, &g_st_report_session_Ref, &g_st_report_moduleRef};

static void __my_free(void **pp_data)
{
    if(pp_data && *pp_data)
    {
        frfree(*pp_data);
//        *pp_data = NULL;
    }
    return;
}


static void __case1(void)
{
    frreport_session_mng_init(0);
    frreport_session_mng_clean();
    frreport_session_mng_destory();
    return;

}


static void __case2(void)
{
    int i_ret = 0;
    Frreport_session_data *p_session_data = NULL;
    Frlist_node *p_st_node = NULL;

    i_ret = frreport_session_mng_init(0);

    frreport_session_mng_setRef(g_st_apm_context.p_st_report_session_ref);

    p_session_data = (Frreport_session_data *)frmalloc(sizeof(Frreport_session_data));
    memset(p_session_data, 0x00, sizeof(Frreport_session_data));

    p_session_data->i_l7_proto = 1;
    p_session_data->p_data = frstrdup("test");

    p_st_node = frlist_node_create(p_session_data);

    frhash2_addLong(g_st_apm_context.p_st_report_session_ref->p_hash_hdr_data, p_session_data->i_l7_proto, p_st_node);


    frreport_session_set(&g_st_apm_context, 1, __my_free);


    frreport_session_mng_clean();
    CU_ASSERT_EQUAL(g_st_apm_context.p_st_report_session_ref->p_hash_hdr_data->ul_node_count, 0);

    frreport_session_mng_destory();
    return;

}




int add_suite_frreport_session_mng_clean(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite("frreport_session_mng frreport_session_mng_clean()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    CU_add_test(pSuite, "case1", __case1);
    CU_add_test(pSuite, "case2", __case2);

    return FR_SUCC;
}
